//-----------------------------------------------------------------------------
// Name: Rifle.cpp
// Auth: Rob Darty
// Desc: Moves a Rifle around in 2D
//-----------------------------------------------------------------------------

#include "Rifle.h"

#include "SharedConstants.h"

#include "corona/corona.h"
#include <iostream>
#include <GL/glut.h>
#include <math.h>

//-----------------------------------------------------------------------------
// Globals:
//-----------------------------------------------------------------------------
cRifle gRifle;


//-----------------------------------------------------------------------------
// Functions:
//-----------------------------------------------------------------------------
cRifle* GetRifle()
{
	return &gRifle;
}

//-----------------------------------------------------------------------------
// class cRifle:
//-----------------------------------------------------------------------------
cRifle::cRifle() :
	mXPosition(0),
	mZPosition(0),
	mYPosition(0),
	mActive(true),
	mDamage(25)
{

}

cRifle::~cRifle()
{
}

//Move rifle
void cRifle::Move(float x, float y, float z)
{
	mXPosition = x;
	mYPosition = y;
	mZPosition = z;
	//printf("%f, %f, %f\n", mXPosition, mYPosition, mZPosition);
}

//Gets rifle's active status
bool cRifle::GetActive()
{
	return mActive;
}

//Sets active status
void cRifle::SetActive(bool a)
{
	mActive=a;
}

//Sets pitch
void cRifle::SetPitch(float p)
{
	mPitch = p;
}

//Sets yaw
void cRifle::SetYaw(float y)
{
	mYaw = y;
}


//Draws Rifle
void cRifle::Draw(float x, float y, float z, float ya, float p)
{	

	mXPosition=x;
	mYPosition=y;
	mZPosition=z;
	mYaw=ya;
	mPitch=p;

	glPushMatrix();
	glTranslatef(mXPosition, mYPosition-.5f, mZPosition);
	glRotatef( mYaw-90, 0.0f, 1.0f, 0.0f );
	glRotatef( mPitch, 0.0f, 0.0f, 1.0f );

	glPushMatrix();
	glTranslatef(0.3f,0.0f, 0.0f);


	GLUquadricObj *pObj;

	pObj = gluNewQuadric();
	gluQuadricNormals( pObj, GLU_SMOOTH );

	glPushMatrix();
		glColor3f( 0.753f, 0.753f, 0.753f );

		glTranslatef( 0.0f, 0.0875f, 0.0f );

		glRotatef( 90.0f, 0.0f, 1.0f, 0.0f );

		gluCylinder( pObj, 0.011f, 0.011f, 0.8f, 10, 10 );

	glPopMatrix();

	glPushMatrix();
		glColor3f( 0.753f, 0.753f, 0.753f );

		glTranslatef( 0.0f, 0.0650f, 0.0f );

		glRotatef( 90.0f, 0.0f, 1.0f, 0.0f );

		gluCylinder( pObj, 0.011f, 0.011f, 0.70f, 10, 10 );

	glPopMatrix();

	
	//Wood barrel container
	glBegin(GL_QUAD_STRIP);

	glColor3f(0.282f, 0.125f, 0.117f);

	glNormal3f(0.0f,0.0f,1.0f);
	glVertex3f(0.25f, 0.0875f, 0.025f);//1
	glVertex3f(0.0f, 0.0875f, 0.025f);//2
	glVertex3f(0.25f, 0.05f, 0.025f);//3
	glVertex3f(0.0f, 0.05f, 0.025f);//4

	glNormal3f(0.0f,-1.0f, 0.0f);
	glVertex3f(0.25f, 0.05f, -0.025f);//5
	glVertex3f(0.0f, 0.05f, -0.025f);//6

	glNormal3f(0.0f,0.0f,-1.0f);
	glVertex3f(0.25f, 0.0875f, -0.025f);//7
	glVertex3f(0.0f, 0.0875f, -0.025f);//8

	glNormal3f(0.0f,1.0f, 0.0f);
	glVertex3f(0.25f, 0.0875f, 0.025f);
	glVertex3f(0.0f, 0.0875f, 0.025f);
	glNormal3f(0.0f,0.0f, 1.0f);
	glVertex3f(0.0f, 0.05f, 0.025f);
	glVertex3f(0.25f, 0.05f, 0.025f);
	

	glEnd();

	glBegin(GL_QUADS);	

	glNormal3f(1.0f, 0.0f, 0.0f);
	glVertex3f(0.25f, 0.1f, 0.025f);
	glVertex3f(0.25f, 0.05f, 0.025f);
	glVertex3f(0.25f, 0.05f, -0.025f);
	glVertex3f(0.25f, 0.1f, -0.025f);

	glEnd();

	//middle metal bit
	glBegin(GL_QUAD_STRIP);
	glColor3f( 0.753f, 0.753f, 0.753f );
	
	glNormal3f(0.0f,0.0f,1.0f);
	glVertex3f(0.0f, 0.0975f, 0.025f);
	glVertex3f(-0.1f, 0.0975f, 0.025f);

	glVertex3f(0.0f, 0.05f, 0.025f);
	glVertex3f(-0.15f, 0.05f, 0.025f);

	glNormal3f(0.0f,0.0f,1.0f);
	glVertex3f(-0.05f, 0.0f, 0.025f);
	glVertex3f(-0.15f, 0.0f, 0.025f);

	glNormal3f(0.0f, -1.0f, 0.0f);
	glVertex3f(-0.05f, 0.0f, -0.025f);
	glVertex3f(-0.15f, 0.0f, -0.025f);

	glNormal3f(0.0f, 0.0f, -1.0f);
	glVertex3f(0.0f, 0.05f, -0.025f);
	glVertex3f(-0.15f, 0.05f, -0.025f);

	glNormal3f(0.0f, 0.0f, -1.0f);
	glVertex3f(0.0f, 0.0975f, -0.025f);
	glVertex3f(-0.1f, 0.0975f, -0.025f);
	
	glNormal3f(0.0f, 1.0f, 0.0f);
	glVertex3f(0.0f, 0.0975f, 0.025f);
	glVertex3f(-0.1f, 0.0975f, 0.025f);

	glEnd();

	glBegin(GL_QUADS);	

	glNormal3f(0.707107f, 0.707107f,0.0f);
	glVertex3f(-0.1f, 0.1f, 0.025f);
	glVertex3f(-0.1f, 0.1f, -0.025f);
	glVertex3f(-0.15f, 0.05f, -0.025f);
	glVertex3f(-0.15f, 0.05f, 0.025f);

	glEnd();

	//thin wooden stock part
	glBegin(GL_QUAD_STRIP);
	glColor3f(0.282f, 0.125f, 0.117f);
	
	glNormal3f(0.0f,0.0f,1.0f);
	glVertex3f(-0.15f, 0.05f, 0.025f);
	glVertex3f(-0.3f, 0.0f, 0.025f);
	glVertex3f(-0.15f, 0.0f, 0.025f);
	glVertex3f(-0.3f, -0.05f, 0.025f);

	glNormal3f(0.316228f, 0.948683f, 0.0f);
	glVertex3f(-0.15f, 0.0f, -0.025f);
	glVertex3f(-0.3f, -0.05f, -0.025f);

	glNormal3f(0.0f, 0.0f, -1.0f);
	glVertex3f(-0.15f, 0.05f, -0.025f);
	glVertex3f(-0.3f, 0.0f, -0.025f);

	glNormal3f(-0.316228f, 0.948683f, 0.0f);
	glVertex3f(-0.15f, 0.05f, 0.025f);
	glVertex3f(-0.3f, 0.0f, 0.025f);

	glEnd();

	//thick wooden stock part
	glBegin(GL_QUAD_STRIP);
	glColor3f(0.282f, 0.125f, 0.117f);
	
	glNormal3f(0.0f,0.0f,1.0f);
	glVertex3f(-0.3f, 0.025f, 0.025f);
	glVertex3f(-0.5f, 0.0f, 0.025f);
	glVertex3f(-0.3f, -0.05f, 0.025f);
	glVertex3f(-0.5f, -0.075f, 0.025f);
	
	glNormal3f(0.124035f, 0.992278f, 0.0f);
	glVertex3f(-0.3f, -0.05f, -0.025f);
	glVertex3f(-0.5f, -0.075f, -0.025f);
	
	glNormal3f(0.0f,0.0f,-1.0f);
	glVertex3f(-0.3f, 0.025f, -0.025f);
	glVertex3f(-0.5f, 0.0f, -0.025f);
	
	glNormal3f(-0.124035f, 0.992278f, 0.0f);
	glVertex3f(-0.3f, 0.025f, 0.025f);
	glVertex3f(-0.5f, 0.0f, 0.025f);

	glEnd();

	glBegin(GL_QUADS);
	glColor3f(0.282f, 0.125f, 0.117f);
	
	glNormal3f(1.0f,0.0f,0.0f);
	glVertex3f(-0.3f, 0.025f, 0.025f);
	glVertex3f(-0.3f, 0.0f, 0.025f);
	glVertex3f(-0.3f, 0.0f, -0.025f);
	glVertex3f(-0.3f, 0.025f, -0.025f);

	glNormal3f(-1.0f, 0.0f, 0.0f);
	glVertex3f(-0.5f, 0.0f, 0.025f);
	glVertex3f(-0.5f, 0.0f, -0.025f);
	glVertex3f(-0.5f, -0.075f, -0.025f);
	glVertex3f(-0.5f, -0.075f, 0.025f);

	glEnd();
gluDeleteQuadric(pObj);
	glPopMatrix();
	glPopMatrix();



}

//GEts rifle damage
int cRifle::GetDamage()
{
	return mDamage;
}
